#转换RGB图像为HSI图像的代码如下：
from skimage import data #data提供测试图片
from matplotlib import pyplot as plt #画图工具
import math
import numpy as np
import sys
#定义RGB图像转换为HSI图像的函数
def rgb2hsi(r,g,b):
    r = r/255
    g = g/255
    b = b/255
    num = 0.5*((r-g)+(r-b))
    den = ((r-g)*(r-g)+(r-b)*(g-b))**0.5
    if b<=g:
        if den == 0:
            den = sys.float_info.min
        h = math.acos(num/den)
    elif b>g:
        if den == 0:
            den = sys.float_info.min
        h = (2*math.pi) - math.acos(num/den)
    s = 1 - (3*min(r,g,b)/(r+g+b))
    i = (r+g+b)/3
    return int(h),int(s*100),int(i*255)
#image = data.imread('flower.jpg')
image = data.coffee() #载入咖啡图像
hsi_image = np.zeros(image.shape,dtype = 'uint8')
for ii in range(image.shape[0]):
    for jj in range(image.shape[0]):
        r,g,b = image[ii,jj,:]
        h,s,i = rgb2hsi(r,g,b)
        hsi_image[ii,jj,:] = (h,s,i)

plt.figure()
plt.axis('off')
plt.imshow(image) #显示RGB原图像
 
plt.figure()
plt.axis('off')
plt.imshow(image[:,:,0],cmap='gray') #显示R分量图像

plt.figure()
plt.axis('off')
plt.imshow(hsi_image[:,:,0],cmap='gray') #显示H分量图像

plt.figure()
plt.axis('off')
plt.imshow(hsi_image[:,:,1],cmap='gray') #显示S分量图像

plt.figure()
plt.axis('off')
plt.imshow(hsi_image[:,:,2],cmap='gray') #显示I分量图像